package cn.jiangjiesheng.bootstrap.gateway.auth;

import cn.hutool.core.codec.Base64;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * Created by dev@jiangjiesheng.cn on 2021/9/26  <br/>
 *
 * @author dev@jiangjiesheng.cn
 */
@RefreshScope
@Data
@Configuration
@ConfigurationProperties(prefix = "auth")
public class AuthFilterProperties {

    /**
     * 模拟登录
     */
    private Mock mock;

    private Boolean enableAccessTokenCache = true;

    /**
     * 不做登录认证的路由
     */
    private Set<String> excludes;

    private Set<String> excludeService;

    @Configuration
    @Data
    @ConfigurationProperties(prefix = "auth.mock")
    public static class Mock {
        private Boolean enabled = false;
        private String enterpriseId = "";
        private String userId = "";
        private String realName = "";
        private String phone = "";
        private String avatar = "";
        private String pinyin = "";
        private String enterpriseName = "";
        private String roleName = "";
        private Integer sex = 0;

        public Map<String, Object> toMap() {
            return new HashMap<String, Object>() {{
                put("enterpriseId", enterpriseId);
                put("userId", userId);
                put("realName", Base64.encode(realName));
                put("phone", phone);
                put("avatar", avatar);
                put("pinyin", pinyin);
                put("enterpriseName", Base64.encode(enterpriseName));
                put("roleName", roleName);
                put("sex", sex);
            }};
        }
    }

}
